package com.srit.yoggsaron.support;

import java.util.List;
import java.util.UUID;

import org.apache.tools.ant.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.srit.yoggsaron.common.JsonQuery;
import com.srit.yoggsaron.db.ProjectMapper;
import com.srit.yoggsaron.db.model.ProjectInfo;
import com.srit.yoggsaron.db.model.User;

@Service
public class ProjectSupport {

	private final Logger logger = LoggerFactory.getLogger(ProjectSupport.class);
	
	@Autowired
	private ProjectMapper _projectMapper;
	public  List<ProjectInfo>  query (   JsonQuery jsonQuery   )throws Exception {
		return  _projectMapper.query(   jsonQuery );  
	}
	public  List<ProjectInfo>  page (   JsonQuery jsonQuery   )throws Exception {
		return  _projectMapper.page(   jsonQuery );  
	}
	public  Long  count (   JsonQuery jsonQuery   )throws Exception {
		return  _projectMapper.count(   jsonQuery );  
	}
	public  Long  insert (   ProjectInfo project  )throws Exception {
		if(project==null )
			throw new Exception("要增加的用户为空 ");
		project.setProjectId( "Project-"+UUID.randomUUID().toString());
		return _projectMapper.update( project );
	}
	
	public  Long  delete (   JsonQuery jsonQuery   )throws Exception {
		if(jsonQuery==null)
			throw new Exception("要删除的用户条件为空");
		Long  result = _projectMapper.delete(  jsonQuery );
		return  result ;
	}
	 
	public  Long  update ( ProjectInfo project )throws Exception {
		if(project==null|| project.getProjectId()  ==null)
			throw new Exception("要修改的用户为空或用户ID为空");
		return _projectMapper.update( project );
	}
	
}
